import 'package:base_app/commons/routes/route_names.dart';
import 'package:base_app/commons/routes/route_pages.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_picker_plus/picker_localizations_delegate.dart';
import 'package:get/get.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
  //     statusBarColor: Colors.transparent,
  //     statusBarIconBrightness: Brightness.dark);
  // SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);

  SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
  runApp(const BaseApp());
}

@pragma("vm:entry-point")
void overlayMain() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(
    const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Material(child: Text("My overlay")),
    ),
  );
}

class BaseApp extends StatefulWidget {
  const BaseApp({super.key});

  @override
  State<BaseApp> createState() => _BaseAppState();
}

class _BaseAppState extends State<BaseApp> {
  final _navigatorKey = GlobalKey<NavigatorState>();

  ThemeData buildTheme(ColorScheme? dynamicScheme, bool isDarkMode) {
    ColorScheme colorScheme =
        dynamicScheme ??
        (isDarkMode ? ColorScheme.dark() : ColorScheme.light());

    return ThemeData(useMaterial3: true, colorScheme: colorScheme);
  }

  @override
  Widget build(BuildContext context) {
    return DynamicColorBuilder(
      builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
        return GetMaterialApp(
          navigatorKey: _navigatorKey,
          debugShowCheckedModeBanner: false,
          localizationsDelegates: const [
            DefaultMaterialLocalizations.delegate,
          ],
          theme: buildTheme(lightDynamic, false),
          darkTheme: buildTheme(darkDynamic, true),
          initialRoute: RouteNames.index,
          getPages: RoutePages.routes,
        );
      },
    );
  }
}
